'use strict'

var _mm = require('util/mm.js');
var _user = {
    //退出
    logout: function (resolve, reject) {
        _mm.request({
            url: _mm.getServerHost('/user/logout.do'),
            method: 'post',
            success: resolve,
            error: reject
        });
    },
    //检查登录
    checkLogin: function (resolve, reject) {
        console.log('checkLogin');
        _mm.request({
            url: _mm.getServerHost('/user/get_user_info.do'),
            method: 'post',
            success: resolve,
            error: reject
        });
    },
    //登录
    login : function(userInfo,resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/login.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    },
    //用户注册
    register : function(userInfo,resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/register.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    },
    //获取密码提示问题
    getQuestion :function(username,resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/forget_get_question.do'),
            method: 'post',
            data : username,
            success: resolve,
            error: reject
        });
    },
    //检查密码提示问题答案是否正确
    checkAnswer :function(userInfo,resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/forget_check_answer.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    },
    // 检查用户名
    checkUsername : function(username, resolve, reject){
        _mm.request({
            url     : _mm.getServerHost('/user/check_valid.do'),
            data    : {
                type    : 'username',
                str     : username
            },
            method  : 'POST',
            success : resolve,
            error   : reject
        });
    },
    resetPassword : function(userInfo,resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/forget_reset_password.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    },
    //获取用户信息
    getUserInfo : function(resolve,reject){
        _mm.request({
            url: _mm.getServerHost('/user/get_information.do'),
            method: 'post',
            success: resolve,
            error: reject
        });
    },
    //修改用户信息
    updateUserInfo :  function(userInfo,resolve,reject){
        console.log('===/user/update_information.do');
        _mm.request({
            url: _mm.getServerHost('/user/update_information.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    },
    //修改密码
    updatePassword : function(userInfo,resolve,reject){
        console.log('===/user/reset_password.do');
        _mm.request({
            url: _mm.getServerHost('/user/reset_password.do'),
            method: 'post',
            data : userInfo,
            success: resolve,
            error: reject
        });
    }
};
module.exports = _user;
